import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0,
    lastUpdated: null
  }),
  actions: {
    increment() {
      this.count++
      this.lastUpdated = new Date().toISOString()
    },
    async incrementAsync(delay = 1000) {
      await new Promise(resolve => setTimeout(resolve, delay))
      this.increment()
    }
  },
  getters: {
    doubleCount() {
      return this.count * 2
    }
  },
  persist: {
    key: 'pinia-counter',
    paths: ['count']
  }
})